home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 024 / conquest / conqmc.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  11KB  |  363 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. depart(starnum)
  7. {
  8.     if ( (tf_stars[starnum][player]+col_stars[starnum][player])>0 )
  9.         en_departures[starnum]=true;
  10. }
  11.  
  12. int
  13. eval_bc_col(planet)
  14. struct stplanet *planet;
  15. {
  16. int i,forces;
  17. int result;
  18.     if ( ! (stars[planet->pstar].visit[ENEMY]) ) {
  19.         result = 600;
  20.     } 
  21.     else {
  22.         switch ( planet->esee_team ) {
  23.  
  24.         case none:
  25.             result=100; 
  26.             break;
  27.  
  28.         case ENEMY:
  29.             if (planet->conquered)
  30.                 result = 1000;
  31.             else {
  32.  
  33.             if ( ((6*planet->amb +planet->mb) <= (planet->iu / 15))
  34.                 && (!((! planet->conquered) 
  35.                 && (planet->iu < mb_cost)))
  36.                 ) {
  37.                 result = 300;
  38.             } 
  39.             else {
  40.                 result = 0;
  41.             };
  42.             };
  43.             
  44.             if (planet->amb >=4) result = result - 250;
  45.             
  46.             break;
  47.  
  48.         case player:
  49.             if ( planet->conquered ) {
  50.                 result = 400;
  51.             } 
  52.             else {
  53.                 result = 200;
  54.             };
  55.             break;
  56.         }; /*switch (*/
  57.         if ( (planet->capacity < 40) && (planet->iu < 15) )
  58.             result = result - 100;
  59.     };
  60.     result = result + rnd(20);
  61.     return (result);
  62. }
  63.  
  64. int
  65. eval_t_col(planet, range)
  66. struct stplanet *planet;
  67. float range;
  68. {
  69.     int result;
  70.     if ( (! stars[planet->pstar].visit[ENEMY]) )
  71.         result=60;
  72.     else {
  73.         switch ( planet->esee_team ){
  74.         case none: 
  75.             result = 40 ;
  76.             break;
  77.         case ENEMY: 
  78.             result= 30 ;
  79.             break;
  80.         case player: 
  81.             result = 0;
  82.         }; /*switch (*/
  83.         if ( (planet->esee_team != player) 
  84.             && (planet->capacity - planet->inhabitants > 40 - 
  85.                                 (turn / 2) ) )
  86.             result = result + 40;
  87.     };
  88.     result -= (int)(2*range + .5);
  89.     return(result);
  90. }
  91.  
  92. inputmach()
  93. {
  94.     int count,tfnum,starnum;
  95.     float slist[nstars+1];
  96.     for ( tfnum= 1 ; tfnum<=26; tfnum++ ) {
  97.         if ( (tf[ENEMY][tfnum].eta==0) && (tf[ENEMY][tfnum].dest!=0) ) {
  98.             starnum = tf[ENEMY][tfnum].dest;
  99.             get_stars(starnum,slist,&count);
  100.             send_scouts(slist,&tf[ENEMY][tfnum]);
  101.             send4transports(slist,&tf[ENEMY][tfnum]);
  102.             move_bc(&tf[ENEMY][tfnum],slist);
  103.             zero_tf(ENEMY,tfnum);
  104.         };
  105.     };
  106. }
  107.  
  108. move_bc(task, slist)
  109. struct sttf *task;
  110. float slist[nstars+1];
  111. {
  112.     int best_star,top_score,starnum,score,factors;
  113.     struct stplanet *pplanet, *best_planet;
  114.  
  115.     if ( (task->b>0) || (task->c > 0) ) {
  116.         for (starnum = 1; starnum <= nstars; starnum++) {
  117.             if (slist[starnum] > 0 ) {
  118.                 best_star = starnum;
  119.                 starnum = nstars + 1;
  120.             };
  121.         };
  122.         best_planet = nil;
  123.         top_score = -1000;
  124.         for ( starnum = 1 ; starnum<=nstars; starnum++ ) {
  125.             if ( (slist[starnum] > 0) || (starnum==task->dest) ) {
  126.                 pplanet = stars[starnum].first_planet;
  127.                 while ( pplanet != nil ) {
  128.                     score = eval_bc_col(pplanet) ;
  129.                     if ( (starnum==task->dest) )
  130.                         score += 250;
  131.  
  132.                     if (tf_stars[starnum][ENEMY] > 0)
  133.                         score -= 150;
  134.  
  135.                     if ( score > top_score ) {
  136.                         top_score = score;
  137.                         best_planet = pplanet;
  138.                         best_star = starnum;
  139.                     };
  140.                     pplanet = pplanet->next;
  141.                 };
  142.             };
  143.         };
  144.         if ( best_star==task->dest ) { /*stay put*/
  145.             if ( best_planet != nil ) {
  146.                 if ( (best_planet->team==ENEMY) 
  147.                     && (best_planet->conquered)
  148.                     && (best_planet->iu < 20)  ) {
  149.                     factors = weapons[ENEMY] * ((task->c*c_guns)+(task->b*b_guns));
  150.                     factors = min( factors, 4 * best_planet->inhabitants);
  151.                     blast(best_planet,factors);
  152.                     if ( (tf_stars[best_planet->pstar][player] > 0 ) ||
  153.                         (col_stars[best_planet->pstar][player] > 0 ) )
  154.                         best_planet->psee_capacity = best_planet->capacity;
  155.                 } 
  156.                 else if ( (best_planet->team==ENEMY) &&
  157.                     (best_planet->conquered) ) { /*decide whether to split*/
  158.                     if ((((task->b > 3) || (task->c > 3) ) && (rnd(4)==4) ) ||
  159.                         (task->b > 8))
  160.                         wander_bc(task,slist);
  161.                 };
  162.             };
  163.         } 
  164.         else { /*move*/
  165.             tf_stars[task->dest][ENEMY]--;
  166.             depart(task->dest);
  167.             task->dest = best_star;
  168.             task->eta = (int)((slist[best_star]-0.01) /
  169.                                 vel[ENEMY])+1;
  170.         };
  171.     };
  172. }
  173.  
  174.  
  175. send4transports(slist, task)
  176. float slist[nstars+1];
  177. struct sttf *task;
  178. {
  179.     int new_tf,to_land,sec_star,sec_score,best_star,top_score,
  180.         score,starnum;
  181.     int xstar;
  182.     struct stplanet *pplan, *best_plan;
  183.     int trash1, trash2;
  184.  
  185.     if ( task->t >0 ) {
  186.         best_star=0;
  187.         sec_star = 0;
  188.         sec_score = -11000;
  189.         top_score = -10000;
  190.         best_plan=nil;
  191.         for ( starnum = 1 ; starnum<=nstars; starnum++ ) {
  192.             if ( (slist[starnum] > 0) || (starnum==task->dest) ) {
  193.                 pplan = stars[starnum].first_planet;
  194.                 while ( pplan != nil ) {
  195.                     score = eval_t_col(pplan,slist[starnum]);
  196.                     xstar = starnum;
  197.                     if ( score > top_score ) {
  198.                         swap(&best_star,&xstar);
  199.                         swap(&top_score,&score);
  200.                         best_plan = pplan;
  201.                     };
  202.                     if ( score > sec_score ) {
  203.                         sec_score = score;
  204.                         sec_star = xstar;
  205.                     };
  206.                     pplan = pplan->next;
  207.                 };
  208.             };
  209.         };
  210.         if ( (best_star == task->dest)  ) { /*land*/
  211.             if ( (tf_stars[best_star][player]==0) && (best_plan->team != player) 
  212.                 ) {
  213.                 trash1 = task->t;
  214.                 trash2 = (best_plan->capacity-best_plan->inhabitants)/3;
  215.                 to_land = min(trash1, trash2);
  216.                 if ( (to_land > 0) ) {
  217.                     if ( (best_plan->inhabitants==0)  ) {
  218.                         best_plan->team = ENEMY;
  219.                         best_plan->esee_team = ENEMY;
  220.                         col_stars[best_star][ENEMY]=col_stars[best_star][ENEMY]+1;
  221.                     };
  222.                     best_plan->inhabitants=best_plan->inhabitants+to_land;
  223.                     best_plan->iu = best_plan->iu + to_land;
  224.                     task->t = task->t - to_land;
  225.                     send4transports(slist,task);
  226.                 };
  227.             };
  228.         } 
  229.         else { /*move*/
  230.             if ( (task->t >= 10) && (sec_star > 0) ) {
  231.                 get_tf(ENEMY,&new_tf,task->dest);
  232.                 tf[ENEMY][new_tf].t = task->t / 2;
  233.                 task->t = task->t - tf[ENEMY][new_tf].t;
  234.                 if ( (task->c >0) && (! underdefended(task->dest)) ) {
  235.                     tf[ENEMY][new_tf].c = 1;
  236.                     task->c = task->c -1;
  237.                 };
  238.                 send2t_tf(&tf[ENEMY][new_tf],slist,best_star);
  239.                 best_star = sec_star;
  240.             };
  241.             get_tf(ENEMY,&new_tf,task->dest);
  242.             tf[ENEMY][new_tf].t = task->t;
  243.             task->t = 0;
  244.             if ( (task->c >0) && (! underdefended(task->dest)) ) {
  245.                 tf[ENEMY][new_tf].c = 1;
  246.                 task->c = task->c -1;
  247.             };
  248.             send2t_tf(&tf[ENEMY][new_tf],slist,best_star);
  249.         };
  250.     };
  251. }
  252.  
  253.  
  254. send2t_tf(task, slist, dest_star)
  255. struct sttf *task;
  256. float slist[nstars+1];
  257. int dest_star;
  258. {
  259.     depart(task->dest);
  260.     task->dest = dest_star;
  261.     task->eta = (int)((slist[dest_star]-0.01)/vel[ENEMY])+1;
  262. }
  263.  
  264.  
  265. send_scouts(slist, task)
  266. float slist[nstars+1];
  267. struct sttf *task;
  268. {
  269.     int dest,new_tf,j,doind;
  270.     int doable[nstars+1];
  271.     if ( task->s > 0 ) {
  272.         doind=0;
  273.         for ( j = 1 ; j<=nstars; j++ ) {
  274.             if ( (! stars[j].visit[ENEMY]) && (slist[j]>0) ) {
  275.                 doind=doind+1;
  276.                 doable[doind]=j;
  277.             };
  278.         };
  279.         while ( (doind>0) && (task->s > 0) ) {
  280.             get_tf(ENEMY,&new_tf,task->dest);
  281.             tf[ENEMY][new_tf].s = 1;
  282.             dest = rnd(doind);
  283.             tf[ENEMY][new_tf].dest = doable[dest];
  284.             tf[ENEMY][new_tf].eta = (int)((slist[doable[dest]]-0.01)/vel[ENEMY])
  285.                 +1;
  286.             depart(task->dest);
  287.             doable[dest] = doable[doind];
  288.             doind = doind-1;
  289.             task->s = task->s -1;
  290.         };
  291.         while ( task->s > 0 ) {
  292.             do {
  293.                 dest= rnd(nstars);
  294.             } 
  295.             while (slist[dest] <= 0);
  296.             get_tf(ENEMY,&new_tf,task->dest);
  297.             tf[ENEMY][new_tf].s=1;
  298.             tf[ENEMY][new_tf].dest = dest;
  299.             tf[ENEMY][new_tf].eta = (int)((slist[dest]-0.01)/vel[ENEMY])+1;
  300.             depart(task->dest);
  301.             task->s = task->s -1;
  302.         };
  303.     };
  304. }
  305.  
  306. boolean
  307. underdefended(starnum)
  308. {
  309.     struct stplanet *pplanet;
  310.     boolean result;
  311.     result = false;
  312.     pplanet = stars[starnum].first_planet;
  313.     while ( (pplanet != nil) && (! result) ) {
  314.         if ( (pplanet->team==ENEMY) && (pplanet->iu > 10) &&
  315.             ((6*pplanet->amb +pplanet->mb) < round(pplanet->iu / 15)) )
  316.             result = true;
  317.         pplanet = pplanet->next;
  318.     };
  319.     return(result);
  320. }
  321.  
  322. wander_bc(task, slist)
  323. struct sttf *task;
  324. float slist[nstars+1];
  325. {
  326.     int ships,i,count,dest,new_tf;
  327.     if ( (task->b>1) || (task->c > 1) ) {
  328.         count = 0;
  329.         for ( i = 1 ; i<=nstars; i++ ) {
  330.             if ( slist[i] != 0 )
  331.                 count = count + 1;
  332.         };
  333.         if ( count > 0 ) {
  334.             dest = rnd(count);
  335.             count = 0;
  336.             i = 0;
  337.             do {
  338.                 i = i + 1;
  339.                 if ( slist[i]>0 ) count = count + 1;
  340.             } 
  341.             while (count != dest);
  342.             get_tf(ENEMY,&new_tf,task->dest);
  343.             ships = task->b / 2;
  344.             tf[ENEMY][ new_tf].b = ships;
  345.             task->b = task->b - ships;
  346.             ships = task->c / 2;
  347.             tf[ENEMY][new_tf].c = ships;
  348.             task->c = task->c - ships;
  349.  
  350.             if (task->t > 3) {
  351.                 tf[ENEMY][new_tf].t = 2;
  352.                 task->t = task->t - 2;
  353.                 };
  354.  
  355.             tf[ENEMY][new_tf].dest = i;
  356.             tf[ENEMY][new_tf].eta = (int)((slist[i]-0.01) / 
  357.                                 vel[ENEMY])+1;
  358.             depart(task->dest);
  359.         };
  360.     };
  361. }
  362.  
  363.